require.config(window.jshead);
require(['jquery', 'pages', 'layer', 'navigator', 'common'], function ($, pg, layer, common) {
    layer.config({
        path: '/js/layer/'
    });


    function getList(param) {
        pg.paging(1, 11, '/user/debt/list', 'transfer', 'transferTemp', param, '', goTo);
    }

    function getList1(param) {
        pg.paging(1, 11, '/user/debt/list', 'transfer1', 'transferTemp1', param, '');
    }

    function getList2(param) {
        pg.paging(1, 11, '/user/debt/list', 'transfer2', 'transferTemp2', param, '');
    }

    $('.transfer_middle_ul').on('click', 'li', function () {
        $(".pages").html('<nav><ul id="pages" style="margin:74px auto"></ul></nav>');
        $(this).addClass('active');
        $(this).siblings().removeClass('active');
        if ($(this).attr("id") == 0) {
            $('.can').show();
            $('.can_ok').hide();
            $('.can_ing').hide();
            var param = {debtStatus: $(this).attr("id")};
            getList(param);

        } else if ($(this).attr("id") == 1) {
            $('.can').hide();
            $('.can_ok').hide();
            $('.can_ing').show();
            var param = {debtStatus: $(this).attr("id")};
            getList1(param);

        } else if ($(this).attr("id") == 2) {
            $('.can').hide();
            $('.can_ing').hide();
            $('.can_ok').show();
            var param = {debtStatus: $(this).attr("id")};
            getList2(param);
        }
    });

    $('.active').trigger('click');
    //这边是分页的内容

    /* var param={debtStatus:0};
     getList(param);*/

    function floatWindow() {
        $('.rebox').hide();
        $('#payPassword_rsainput').val('');
        $(".guangbiao").css({"left": 0});
        $(".sixDigitPassword").find("i").find("b").css({"display": "none"});
    }

    //点击下拉箭头获取数据
    $('.down1').bind('click', function () {

        if ($('.infoAll').is(':hidden')) {
            $('.infoAll').show();
            $('.down1').removeClass("pull");
            $('.down1').addClass('push');
        } else {
            $('.infoAll').hide();
            $('.down1').removeClass("push");
            $('.down1').addClass('pull');
        }
    })

    var zhangId = "";
    function goTo() {
        $('.zhuanrang1').on('click', function () {
            $('select').val('0');
            $('.rebox').show(300);
            $("#payPassword_rsainput").focus();
            //点击关闭按钮弹窗关闭
            $('.close112').bind('click', floatWindow)
            //调用ajax获取数据
            zhangId=$(this).parent().attr('id');
            $.ajax({
                type: 'post',
                url: '/user/debt/detail',
                dataType: 'json',
                data: {
                    id: zhangId
                },
                success: function (data) {
                    if (data.result = 'success') {
                        $('.InterestReceived').html(data.repayAmount + '元');
                        $('.InterestUnpaid').html(data.notRepayAmount + '元');
                        $('.nextCheck').html(Common.changemsTodate(data.collectTime));
                    }
                }
            });
            //获取到页面中的钱
            var money = $(this).attr('data-investAmount');
            $('.TransferAmount').html(money + '元');
            //给select选项框绑定事件
            $('select').bind('change', function () {
                var options = $("select option:selected").val();
                var money1 = (100 - options) * money / 100
                $('.TransferAmount').html(money1 + '元');
            })
        })
    }
    /*获取到input输入框中的值*/
    $('#tijao').bind('click', function () {
        var getValue = $('#payPassword_rsainput').val();
        var options = $("select option:selected").val() / 100;
        var reg = new RegExp("^[0-9]*$")
        if (!reg.test(getValue)) {
            layer.tips('请输入数字', '#payPassword_rsainput');
            setTimeout("$('#payPassword_rsainput').val('')", 1000);
        } else if (getValue.length != 6) {
            layer.tips('请输入6位数字密码', '#payPassword_rsainput');
            setTimeout("$('#payPassword_rsainput').val('')", 1000);
        } else {
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                type: 'post',
                url: '/user/debt/addDebt',
                data: {
                    payPassword: getValue,
                    discountRate: options,
                    investId: zhangId
                },
                dataType: 'json',
                success: function (data) {
                    layer.close(index);
                    if (data.result == 'success') {
                        $('#tijao').attr('disabled')
                        layer.msg('成功');
                        // function jump() {
                        //     window.location.href = '/transfer?1?6?9'
                        // }
                        // window.setTimeout(jump, 1000);
                        getList({debtStatus:0});
                        getList1({debtStatus:1});
                        getList2({debtStatus:2});
                        floatWindow()//点击关闭按钮弹窗关闭
                    } else {
                        floatWindow()//点击关闭按钮弹窗关闭
                        layer.msg(data.respMsg);
                        $('#payPassword_rsainput').val('');
                        $(".guangbiao").css({"left":0});
                        $(".sixDigitPassword").find("i").find("b").css({"display":"none"});
                    }
                }
            })
        }
    })
    //支付密码
    $("#payPassword_rsainput").bind("blur", function (){
        $(".sixDigitPassword span").removeClass("guangbiao");
    });
    $("#payPassword_rsainput").bind("focus", function (){
        $(".sixDigitPassword span").addClass("guangbiao");
        if($(".i-text").val().length==6){
            $(".guangbiao").css({"left":($(".i-text").val().length-1)*50});
        }else{
            $(".guangbiao").css({"left":($(".i-text").val().length)*50});
        }
    });
    $(".i-text").keyup(function () {
        var inp_v = $(this).val();
        var inp_l = inp_v.length;
        //$("p").html( "input的值为：" + inp_v +"; " + "值的长度为:" + inp_l);//测试用

        for (var x = 0; x <= 6; x++) {
            //$("p").html( inp_l );//测试
            $(".sixDigitPassword").find("i").eq(inp_l).prevAll("i").find("b").css({"display": "block"});
            $(".sixDigitPassword").find("i").eq(inp_l - 1).nextAll("i").find("b").css({"display": "none"});
            $(".guangbiao").css({"left": inp_l * 50});//光标位置
            if (inp_l == 0) {
                $(".sixDigitPassword").find("b").css({"display": "none"});
                $(".guangbiao").css({"left": 0});
            }
            else if (inp_l == 6) {
                $(".sixDigitPassword").find("b").css({"display": "block"});
                $(".guangbiao").css({"left": 5 * 50});
            }
        }
    });
    //支付页回车事件
    $(".rebox").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            $('#determine').click();
        }
    });

});